class Solution {
public:
    int findWinningPlayer(vector<int>& skills, int k) {
        if(k >= skills.size()){
            int ret = 0;
            for(int i = 0;i < skills.size();i++) {
                if(skills[i] > skills[ret])
                ret = i;
            }
            return ret;
        }
        vector<int> spos(skills.size());
        for(int i =0;i < skills.size();i++) spos[i] = i;
        int num = 0;
        int top = 0;
        for(int i = 1;num != k;i++){
            if(skills[spos[i]] >skills[spos[top]])
            {
                spos.push_back(top);
                top = i;
                num = 1;
            }else{
                spos.push_back(i);
                num++;
            }
        }
        return top;
    }
};